/*
 * Copyright 2004 original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jbfilter.core.factory;

import org.apache.commons.lang.StringUtils;


/**
 * The registry for the {@link FilterProvider}'s. The filter providers can be retrieved by NAME or by CLASSNAME.
 * The class name is the fully (package) qualified name of the provider class. For the implementations that ship with
 * jbfilter, the providers are registered by the name which is the third part of the package name :
 * org.jbfilter.bean --> bean, org.jbfilter.hibernate --> hibernate...
 * You don't need to register them, they are automatically registered (by NAME only). You can register your custom providers by NAME or by CLASSNAME using the
 * two {@code register()} methods.
 * @author Marcus Adrian
 */
public final class FilterProviderRegistry extends GenericRegistry<FilterProvider>{
	private FilterProviderRegistry() {
		super();
	}
	private static enum SingletonHolder {
		INSTANCE;
		private FilterProviderRegistry registry = new FilterProviderRegistry();
	}
	public static FilterProviderRegistry getInstance() {
		return SingletonHolder.INSTANCE.registry;
	}
	@Override
	protected String getClassNameFromName(String name) {
		return String.format("org.jbfilter.%s.factory.Filter%ss", name, StringUtils.capitalize(name));
	}
	/**
	 * Retrieve the provider by NAME. See explanations on class comment.
	 * @param name the name, i.e. "bean", "hibernate", "jpa"...
	 * @return
	 */
	@Override
	public FilterProvider fromName(String name) {
		return super.fromName(name);
	}
	/**
	 * Retrieve the provider by CLASSNAME. See explanations on class comment.
	 * Note that the providers that ship with the jbfilter libraries are NOT registered by CLASSNAME.
	 * Use {@link #fromName(String)} to retrieve them by NAME. Or register them manually with {@link #register(FilterProvider)} if
	 * you really must retrieve them by CLASSNAME.
	 * @param className the fully (package) qualified name of the provider class
	 * @return
	 */
	@Override
	public FilterProvider fromClassName(String className) {
		return super.fromClassName(className);
	}
	/**
	 * Register by NAME.
	 * @param name the name used to retrieve the provider later
	 * @param provider
	 */
	@Override
	public void register(String name, FilterProvider provider) {
		super.register(name, provider);
	}
	/**
	 * Register by CLASSNAME.
	 * @param provider
	 */
	@Override
	public void register(FilterProvider provider) {
		super.register(provider);
	}
	
}
